package com.feifei.controller;

import com.feifei.bean.Comment;
import com.feifei.service.CommentService;
import com.feifei.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;


@CrossOrigin
@Controller
public class CommentController {
    @Autowired
    CommentService commentService;

    @ResponseBody
    @RequestMapping("/comment/addComment")
    public Result addComment(@RequestBody Comment comment) {
        System.out.println("comment = " + comment);
        Result result = new Result();
        if (comment.getContent() != "") {
            comment.setCreateTime(new Date());
            int i = commentService.addComment(comment);
            if (i > 0) {
                result.setMsg("评论成功");
                result.setStatus(true);
                return result;
            }
        }
        result.setMsg("评论失败");
        result.setStatus(false);
        return result;
    }
}
